package com.drcoffee.drcoffeemall.controller;

import com.alipay.api.AlipayApiException;

import com.drcoffee.drcoffeemall.entry.Result;
import com.drcoffee.drcoffeemall.mapper.OrderMapper;
import com.drcoffee.drcoffeemall.service.AliPayService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/pay")
public class AliPayController {


    @Autowired
    OrderMapper orderMapper;


    @Autowired
    AliPayService payService;


    /*
     * 支付网站扫码支付接口-统一下单支付接口
     */
    @GetMapping("/aliPay")
    private String aliPay(@RequestParam String order_code) throws AlipayApiException {
        return payService.aliPay(order_code);
    }


    /*
     * 支付宝服务器异步通知页面
     */
    @PostMapping("/notify")
    public String alipayNotify(HttpServletRequest request, String out_trade_no, String trade_no, String total_amount, String gmt_payment) {
        return payService.alipayNotify(request, out_trade_no, trade_no, total_amount, gmt_payment);
    }

    /*
     * 支付宝服务器同步通知页面
     */
    @GetMapping("/return")
    public void alipayReturn(HttpServletRequest request, String out_trade_no, String trade_no, String total_amount, String timestamp, HttpServletResponse response) {
        payService.alipayReturn(request, out_trade_no, trade_no, total_amount, timestamp, response);
    }

    /*
     * 支付宝退款
     */
    @GetMapping("/aliRefund")
    public void aliRefund(@RequestParam String order_code) throws AlipayApiException {
        payService.aliRefund(order_code);
    }


}
